/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jpaintball;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author ondra
 */
public class JoinDialog extends JDialog {

    JTextField port;
    JTextField host;
    JButton    joinButton;
    GameWindow owner;

    JoinDialog(GameWindow _owner) {

        super(_owner, true);
        this.setTitle("Join network game");
        setResizable(false);
        this.setLayout(new FlowLayout());
        this.setSize(200, 200);

        owner = _owner;

        // add components
        host = new JTextField("127.0.0.1");
        port = new JTextField("2222");
        joinButton = new JButton("Join!");
        joinButton.addActionListener(new JoinButtonAction());
        add(new JLabel("Host"));
        add(host);
        add(new JLabel("TCP Port:"));
        add(port);
        add(joinButton);

        //add(new JTextField());

        this.pack();

        // center window
        setLocationRelativeTo(null);

        setVisible(true);
    }

    private class JoinButtonAction implements ActionListener {

        public void actionPerformed(ActionEvent arg0) {
            owner.joinGame();
            JoinDialog.this.setVisible(false);
        }

    }

}
